import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import nslookup.*;


public class Main
{

	/**
	 * @param args
	 */
	public static void processCommandLineArgs(String[] args)
	{
		DnsLookup nslookup = new DnsLookup();
		
		for(int i = 0; i < args.length; i++)
		{
			System.out.println(nslookup.lookup(args[i]));
		}
	}
	
	public static void commandLineInterface ()
	{
		BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
		String exit = "exit";
		String input = "";
		DnsLookup nslookup = new DnsLookup();
		System.out.println("Enter a hostname or ip address, or 'exit' to quit:");
		
		while(true)
		{
			System.out.print(">");
			try
			{
				input = new String();
				input = cin.readLine();
				
				if(input.equals(exit))
					break;
				
				System.out.println(nslookup.lookup(input));
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	
	public static void main(String[] args)
	{
		if(args.length != 0)
			Main.processCommandLineArgs(args);
		else
			Main.commandLineInterface();
	}

}
